import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useSystemInfo = defineStore('system', () => {
  const navBarInfo = reactive({
    navBarHeight: 0, // 导航栏高度
    menuTop: 0, // 胶囊距底部间距（保持底部间距一致）
    menuHeight: 0, // 胶囊高度（自定义内容可与胶囊高度保证一致）
    maxWidth:0,
  });

  const safeArea = reactive<any>({})
  /**
   * @description 计算导航栏信息
   */
  function calcNavBarInfo() {
    // 获取系统信息
    const systemInfo = uni.getWindowInfo() as any;
    console.log("systemInfo",systemInfo);
    Object.assign(safeArea,systemInfo.safeArea);

    // 胶囊按钮位置信息
    const menuButtonInfo = uni.getMenuButtonBoundingClientRect();
    
    // 导航栏高度 = 状态栏高度 + 44
    navBarInfo.navBarHeight = systemInfo.safeArea.top +  navBarInfo.menuHeight + 10;
    navBarInfo.menuTop = menuButtonInfo.top;
    navBarInfo.menuHeight = menuButtonInfo.height;
    navBarInfo.maxWidth = menuButtonInfo.left;
  }

  return {
    calcNavBarInfo, navBarInfo,safeArea
  }
}, {
  unistorage: true, // 是否持久化
})
